/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022.
 * Description: support dim kernel
 * Author: chenjingwen6 <chenjingwen6@huawei.com>
 * Create: 2022-08-05
 */

#ifndef RTOS_DIM_KERNEL_H
#define RTOS_DIM_KERNEL_H
#ifdef CONFIG_JUMP_LABEL
#include <linux/jump_label.h>
#endif
#ifdef CONFIG_LIVEPATCH
#include <linux/livepatch.h>
#endif
#include <linux/types.h>

extern unsigned long dim_kernel_text_start(void);
extern unsigned long dim_kernel_text_end(void);
extern bool is_modules_list_head(const struct list_head *head);

#ifdef CONFIG_JUMP_LABEL
extern struct jump_entry *dim_jump_label_start(void);
extern struct jump_entry *dim_jump_label_end(void);
extern void dim_jump_label_lock(void);
extern void dim_jump_label_unlock(void);
#endif

#ifdef CONFIG_LIVEPATCH
enum klp_notifier_state {
	KLP_NOTIFIER_PATCH,
	KLP_NOTIFIER_UNPATCH,
};

extern int register_klp_notifier(struct notifier_block *nb);
extern int unregister_klp_notifier(struct notifier_block *nb);
extern void klp_notifier_call_chain(enum klp_notifier_state state, struct klp_patch *patch);
#endif /* CONFIG_LIVEPATCH */

#ifdef CONFIG_RTOS_DIM_KERNEL_KEXEC
#include <linux/kexec.h>
extern void dim_add_kexec_buffer(struct kimage *image);
extern int setup_dim_buffer(const struct kimage *image, void *fdt,
			    int chosen_node);
extern void remove_dim_buffer(void *fdt, int chosen_node);

typedef int (*fn_dim_kexec_store_cb)(struct kexec_buf *kbuf);
typedef int (*fn_dim_kexec_restore_cb)(const void *kexec_buffer, size_t kexec_buffer_size);
extern int dim_set_kexec_store_cb(fn_dim_kexec_store_cb store_callback);
extern void dim_clear_kexec_store_cb(void);
extern void dim_restore_from_kexec(fn_dim_kexec_restore_cb restore_callback);
#endif

#ifdef CONFIG_RTOS_DIM_KERNEL_RESPONSE
extern bool get_dim_kernel_response_enabled(void);
#endif

#endif /* RTOS_DIM_KERNEL_H */
